﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace _5._1
{


    public partial class Form1 : Form
    {

        private ArrayList primes = new ArrayList();
        public Form1()
        {
            InitializeComponent();
        }


        private void getPrimes(int min, int max)
        {
            bool nums;
            for (int j = 2; j < max; j++)
            {
                nums = true;
                for (int i = 2; i < j; i++)
                {
                    if (j % i == 0)
                    {
                        nums = false;
                        break;
                    }
                }
                if (nums == true)
                {
                    primes.Add(j);
                }
            }
        }

        private void caculate(int min, int max) {
            ArrayList nums = new ArrayList();
            int flags = 0;
            for (int i = min; i <= max; i++)
            {
                nums.Add(i);
                flags++;
            }
            try
            {
                for (int i = 0; i < primes.Count; i++)
                {
                    if (flags <= 0) { break; }
                    for (int j = i; j < primes.Count; j++)
                    {
                        if (flags <= 0) { break; }
                        int currentNum = (int)primes[i] + (int)primes[j];
                        for (int k = 0; k < nums.Count; k++)
                        {
                            if ((int)nums[k] == currentNum)
                            {
                                string str = "编号:" + flags + "  " + (int)nums[k] + " = " + (int)primes[i] + " + " + (int)primes[j] + "\n";
                                richTextBox1.Text = richTextBox1.Text + str;
                                flags--;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }
    

        private void button1_Click(object sender, EventArgs e)
        {
            getPrimes(6, 100);
            caculate(6, 100);
        }
    }
}
